package com.pulyka.rtpvp.engine.client.web.ui.client.gameview;

public class Vector2d {
	
	public final static Vector2d zero = new Vector2d(0, 0);
	public final static Vector2d north = new Vector2d(0, 1);
	public final static Vector2d south = new Vector2d(0, -1);
	public final static Vector2d west = new Vector2d(-1, 0);
	public final static Vector2d east = new Vector2d(1, 0);
	public final static Vector2d northwest = ViewMath.addVectors(north, west);
	public final static Vector2d southhwest = ViewMath.addVectors(south, west);
	public final static Vector2d southeast = ViewMath.addVectors(south, east);
	public final static Vector2d northeast = ViewMath.addVectors(north, east);
	

	protected double[] xy;
	
	public Vector2d(Vector2d copy) {
		this.xy = new double[]{copy.xy[0], copy.xy[1]};
	}
	
	public Vector2d(float theta, double length){
		xy = ViewMath.getXYComponentOfTheta(theta);
		xy[0] *= length;
		xy[1] *= length;
	}
	
	public Vector2d(float theta){
		xy = ViewMath.getXYComponentOfTheta(theta);
	}
	
	public Vector2d(double x, double y) {
		super();
		this.xy = new double[]{x,y};		                     
	}
	
	public Vector2d getHeadingVector(){
		return new Vector2d(getAngle());
	}
	
	public float getAngle(){
		return (float) ViewMath.getTheta(xy[0], xy[1]);
	}

	public double getX() {
		return xy[0];
	}

	public void setX(double x) {
		this.xy[0] = x;
	}
	
	public double getY() {
		return xy[1];
	}
	
	public void setY(double y) {
		this.xy[1] = y;
	}	
	
	public void multiply(double scalar){
		xy[0] *= scalar;
		xy[1] *= scalar;
	}
	
	public void add(Vector2d other){
		xy[0] += other.xy[0];
		xy[1] += other.xy[1];
	}
	
}
